home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / byte0387.arc / DAWSON.ARC / SIMPP.DOC < prev    next >
Encoding:
Text File  |  1985-07-12  |  14.5 KB  |  355 lines

  1. /*************************************************************************
  2.  
  3.  |===================================================================|
  4.  |            SIMPP = Simple IMage Processing Package.               |
  5.  |                                                                   |
  6.  |             Copyright (c) 1987, Benjamin M. Dawson                |
  7.  |                     Edit 1.2 : Jan. 30, 1987                      |
  8.  | This package may be freely copied, modified, and used for non-    |
  9.  | commercial purposes.  No guarantee is made that this code is      |
  10.  | correct or suitable for any purpose.  This notice, including the  |
  11.  | copyright notice, must appear in all copies and modifications.    |
  12.  |===================================================================|
  13.  
  14.  
  15. I. Introduction
  16.  
  17. SIMPP (Simple IMage Processing Package) is a model image processing package
  18. that demonstrate some important and basic algorithms in image processing.
  19.  
  20. It is written in "standard" (K&R) C and has been compiled and tested on:
  21.   (1) an IBM Personal Computer/AT using the Computer Innovations Inc. C
  22.     compiler (Big model) and an Imaging Technology Inc. Series 100 frame
  23.     memory.
  24.   (2) A DEC VAX 11/750 computer using the Berkeley Unix (4.2) C compiler
  25.     an Adage 3000 (Ikonas) image processor.
  26.  
  27. Please see my article in the March, 1987 edition of BYTE magazine ("An
  28. Introduction to Image Processing Algorithms") for details on the package
  29. and algorithms.
  30.  
  31.  
  32. II. Hardware Requirements
  33.  
  34. SIMPP assumes that you have simple image processing hardware on your
  35. computer that can acquire, store, access, and display images with 8 bits
  36. of grey-level intensity.  In particular, this hardware must be able to:
  37.  
  38. 1.  Acquire and store a single picture (a "frame") from an image source
  39. (e.g. TV camera, disk, etc.), with an intensity resolution of 8 bits.  This
  40. will give a pixel values ranging from 0 to 255.  Intensities above 255
  41. are clipped to 255, and intensities below 0 are clipped to 0.  These data
  42. are put into the "image memory".
  43.  
  44. 2.  Access (read and write) this image memory on a pixel-by-pixel basis, as
  45. if the picture values were stored in a large matrix of XSIZE columns by
  46. YSIZE rows.  I suggest a minimum size of YSIZE = 256 rows and XSIZE = 256
  47. columns.
  48.  
  49. The pixels are organized by "video" coordinates: x values increase from left
  50. to right, and y values increase from top to bottom.  Thus coordinate (0,0)
  51. is at the top,left of the image and (XSIZE-1,YSIZE-1) is the bottom,right
  52. point in the image.  The image points must be in normal order rather than
  53. in interlace or any other order.
  54.  
  55. 3.  Display the pixel values on an RGB or monochrome television monitor or
  56. other display device (e.g., EGA, printer, etc.).
  57.  
  58. If your hardware has transformation tables ("Look-Up Tables" or LUTs) for
  59. transforming the output pixel values before they are displayed, the SIMPP
  60. package can use these tables.  Normally these LUTs map a single (monochrome)
  61. pixel value to a red, green, blue triple of values.  This allows image
  62. memory values to be displayed as arbitrary colors (pseudo-color)
  63.  
  64.  
  65. III. Software Setup
  66.  
  67. In order to use SIMPP, you will need to:
  68.   1. Modify the "simpp.h" header to define your hardware to the software.
  69.   2. Write a set of interface routines that access your hardware.
  70.   3. Deal with porting the software to your machine.
  71.   4. Compile and link the software.
  72.  
  73. 1. Values in the header "simpp.h" specify the hardware you are using to the
  74. SIMPP software.  Here is an annotated copy of the header, showing items you
  75. may want to modify (Set off by !! at the beginning of the line):
  76.  
  77. /*********************************************\
  78. *                           *
  79. *    simpp.h = Include file for SIMPP          *
  80. *    For Simple IMage Processing Package.     *
  81. *    Copyright (c) 1987, Benjamin M. Dawson.  *
  82. *      Edit Version: 1.1 : Jan-29-87          *
  83. *                           *
  84. \*********************************************/
  85.  
  86. !! (1) The VOID definition indicates that no useful value is returned from
  87. !! by the function.  This helps document the function and mollifies some
  88. !! automatic code checkers.
  89. /* Type definitions */
  90. #ifndef VOID            /* VOID: No useful return from function */
  91. #define VOID
  92. #endif
  93.  
  94. !! (2) These definitions specify image memory size and structure.
  95. /* Storage definitions.  May need to be changed for your hardware!! */
  96. !!  Each pixel (individual image point) is stored in a 8-bit byte,
  97. !!  even if the hardware acquires fewer bits.  For example, if you
  98. !!  have 6-bit pixels, they still must occupy a byte.  A pixel can
  99. !!  occupy more than a byte (a short, for example), but you might
  100. !!  run out of heap space (internal buffers) on a "small" machine.
  101. !!  Try not to change this item.
  102. #define PIXEL unsigned char    /* Pixel type must be an 8-bit value! */
  103.  
  104. !!  The size of pixel.  This is for 8-bit values.  If your pixels have
  105. !!  fewer bits, change accordingly.  For example, for 6-bit pixels,
  106. !!  define PIXEL_SIZE to be 64.
  107. #define PIXEL_SIZE 256        /* Size of pixel */
  108.  
  109. !!  The minimum pixel value.  Leave this at 0, if you can.
  110. #define MINPIX (PIXEL)0        /* Minimum pixel value */
  111.  
  112. !!  The maximum pixel value is automatically computed.  DON'T CHANGE THIS!
  113. #define MAXPIX (PIXEL)(PIXEL_SIZE-1)    /* Maximum pixel value */
  114.  
  115. !!  Starting index for the image memory.  Leave these at 0, if you can.
  116. #define XSTART 0        /* Starting image memory X address */
  117. #define YSTART 0        /* Starting image memory Y address */
  118.  
  119. !!  Change this to indicate the horizontal size of your image memory.
  120. #define XSIZE 512        /* Horizontal (row) size of image memory */
  121.  
  122. !!  Change this to indicate the vertical size of your image memory.
  123. #define YSIZE 480        /* Vertical (column) size of image memory */
  124.  
  125. !!  Automatic definitions.  DON'T CHANGE THESE!
  126. #define XEND XSIZE-1        /* Last horizontal pixel address */
  127. #define YEND YSIZE-1        /* Last vertical pixel address */
  128.  
  129. !! (3) Define CHECK if you want software checking of arguments ranges.
  130. !! A good idea for debugging!
  131. /* Option switches */
  132. #define CHECK            /* Define CHECK for bounds checking */
  133.  
  134. !! (4) These define return values for error reporting.
  135. /* Return values */
  136. #define ERROR -1        /* Error return */
  137. #define OK 0            /* Return OK */
  138.  
  139. !! (5) These define the maximum kernel size for the convolution, and values
  140. !! specifying how the output of the convolution will be processed.
  141. /* Convolution switches */
  142. !!  This specifies the maximum kernel size.  Used for checking arguments.
  143. #define MAX_KERNEL_SIZE 8    /* Maximum size of kernel */
  144.  
  145. !!  These specify how to process the result of the convolution.
  146. #define    SIGNED 0        /* Don't change convolution output */
  147. #define POSITIVE 1        /* Output + values only. - set to 0 */
  148. #define NEGATIVE 2        /* Set + values to 0, output - of - values */
  149. #define ABSOLUTE 3        /* Output absolute values */
  150.  
  151. !! (6) External procedure declarations.  Don't change.
  152. /* External declarations */
  153. extern PIXEL read_pixel();
  154. extern PIXEL read_LUT();
  155.  
  156. !! (7) Change these values to specify the hardware you are using.
  157. /* CPU and image memory (image processor) specific definitions */
  158. !!  MEMSIZE is the largest possible buffer you can allocate in your
  159. !!  CPU.  This size limits the size of the geometric transformations
  160. !!  and some other operations.  For the IBM AT or PC, with CII Big this
  161. !!  is 2^16-20, as shown below.  Other CPUs and operating systems may
  162. !!  allow a larger value.
  163. #define MEMSIZE 65516L        /* Size of largest buffer for CII Big model */
  164.  
  165. !!  The output values from the convolution routine are scaled (divided
  166. !!  by using a shift function.  Some machines fill with the sign bit on
  167. !!  a right shift (divide by 2) and others don't.  Define this if your
  168. !!  machine does NOT sign fill on right shift.
  169. #undef NO_SIGN_FILL        /* Define if CPU does NOT fill with sign */
  170.                 /* bits on a right shift (see convolution) */
  171.  
  172. !!  If your image memory (image processing board) has output LUTs that allow
  173. !!  a pixel to be transformed into a red,green,blue triple of values for
  174. !!  display on a color monitor, then define LUTS to use these LUTs.  If you
  175. !!  define this and don't have LUTs, the only damage is larger code.
  176. #define LUTS            /* Define LUTS if you have output LUTS */
  177. #ifdef LUTS
  178. !!  These select an output LUT for modification.
  179. #define RED 1            /* Select RED LUT */
  180. #define GREEN 2            /* Select GREEN LUT */
  181. #define BLUE 3            /* Select BLUE LUT */
  182. #endif
  183.  
  184. /* ================ End of simpp.h ================ */
  185.  
  186.  
  187. 2. You must write a set of "interface" routines that link the SIMPP package
  188. with your image memory or image processing hardware.  These routines are
  189. gathered in the "siminter.c" module.
  190.  
  191. The interface routines are specified below, but not given in this package,
  192. as they will be machine specific.  A "dummy" version of "siminter.c" is
  193. provided to help you write a version specific to your hardware.
  194.  
  195. Primitives:
  196.  
  197. int sim_open()
  198.      Opens and initializes the imaging hardware.  Returns ERROR or OK.
  199.  
  200. int sim_close()
  201.      Closes the imaging hardware.  Returns ERROR or OK.
  202.  
  203. VOID acquire()
  204.      Acquires one image into the image memory and returns when done.
  205.  
  206. PIXEL read_pixel(x,y)    
  207.  int x,y;
  208.      Returns the value of the pixel in location (x,y) of the image memory.
  209.  
  210. VOID write_pixel(x,y,z)
  211.  int x,y;
  212.  PIXEL z;
  213.      Writes a new pixel value, z, to location (x,y) in the image memory.
  214.  
  215. VOID write_LUT(color,loc,value)
  216.  int color,loc;
  217.  PIXEL value;
  218.      Set the location specified by loc in the look-up table specified by
  219.      color to value.  If you don't have (or use) LUTs, this should be a
  220.      dummy routine.
  221.  
  222.  
  223. 3. Porting the software to your machine.
  224.  
  225. I have tried to make the SIMPP package as portable as possible, sometimes at
  226. the expense of performance.  Hopefully this will make it easy to port to your
  227. particular compiler, CPU, and image processing hardware.
  228.  
  229. Some notes:
  230.  
  231.      -- Differences in image processing hardware and host CPU are indicated
  232.     by #define's in "simpp.h", as noted above.  You might have to add some
  233.     #defines for your hardware and compiler.
  234.  
  235.      -- You will probably have a lot of trouble if your machine does not
  236.     have an 8-bit byte (e.g. a PDP-8).  Then again, you probably don't
  237.     have a C compiler!
  238.  
  239.      -- Your C compiler must be reasonably complete.  It if follows the K&R
  240.     standard, you should have no problems.  Data types used include:
  241.         unsigned char
  242.         char
  243.         int        (assumed to be short where necessary)
  244.         long        (cast to long where necessary)
  245.         double
  246.  
  247.      -- Elements of the "standard" C I/O library used include:
  248.         "stdio.h"
  249.         malloc() and free()
  250.         printf(), fprintf(), and scanf()
  251.         open(), read(), write()
  252.         exit()
  253.     You may have to change these calls to use your compiler's versions.
  254.     For example, under some versions of Whitesmiths' C on the PDP-11,
  255.     printf() becomes putfmt(), and the %d field specifier becomes %i.
  256.  
  257.   malloc:
  258.     It is assumed that malloc() takes an argument of type: unsigned int.
  259.     If your C library requires this argument to be a long and your type
  260.     int is not equal to a long, then calls to malloc must be changed.
  261.  
  262.     If you don't have malloc() and free(), then you can change the code
  263.     to use static buffers.  You may not be able to use the geometric
  264.     transforms, as they malloc large buffers.
  265.  
  266.   open:
  267.     The arguments to open vary from library to library.  This distribution
  268.     shows them as appropriate for Berkeley 4.2 Unix.  You may have to
  269.     change the READ_ONLY and WRITE_ONLY definitions, and reduce the
  270.     number of arguments to open() from 3 to 2 (drop the 0777 argument).
  271.  
  272.   exit:
  273.     The argument to exit indicates what kind of error is returned to
  274.     the system.  The arguments are defined for Berkeley 4.2 Unix in
  275.     this distribution.  You may have to change them to something
  276.     appropriate for your system.
  277.  
  278.      --    If your compiler does not use ASCII to encode characters, you may
  279.     have to modify the matches() routine in "simtest.c"
  280.  
  281.      -- All routine names are different in the first 8 characters.  You
  282.     may have to these and/or internal variable names to meet the
  283.     requirements of your compiler.  If your compiler only has 6 character
  284.     names, you may have to change the subroutine names.
  285.  
  286. 4. Compiling and linking the software.
  287.  
  288. This SIMPP distribution (version 1.1 -- January 1987) consists of the following
  289. files:
  290.     makefile    = A Unix-style file for making the test program.
  291.     readme        = A short note as to the contents of the directory.
  292.     simarea.c    = Area image processing functions.
  293.     simgeo.c    = Geometric image processing functions.
  294.     siminter.c    = Model hardware interface routines.
  295.     simmeas.c    = Image measurement functions.
  296.     simpoint.c    = Point image processing routines.
  297.     simpp.doc    = This document.
  298.     simpp.h        = Hardware definition header file.
  299.     simsubs.c    = Subroutines for test program.
  300.     simtest.c    = Test program.
  301.     simutil.c    = Utility programs.
  302.  
  303. The C modules (.c) are compiled in the normal fashion and linked with your
  304. main program.  The test program ("simtest.c") contains a main() call, so
  305. you can link with this for a executable program.  The "makefile" can be used
  306. or modified to automatically build the software and test program.
  307.  
  308. If you use the test program (simtest.c), the gaussian burn function (in
  309. simsubs.c) requires the calculation of an exponential.  This is usually
  310. covered by the inclusion of a math library.
  311.  
  312. Table 1 in the BYTE article contains a list of functions in each module,
  313. except for simtest.c and simutil.c.
  314.  
  315.  
  316. IV. Testing the software.
  317.  
  318. A rather extensive test program, "simtest.c" is included.  This uses a
  319. menu to select operations and also has an automatic test sequence.  You
  320. may want to use this program as a starting point for your program, and you
  321. certainly should use it to see that you have ported and compiled everything
  322. correctly.
  323.  
  324. The test program was used to process some of the images in the BYTE article.
  325.  
  326.  
  327. V.  Notes
  328.  
  329. The individual files in this package are separated by the special character
  330. sequence:
  331. /* <-- FILE BREAK --> */
  332. This helps separate the files if they are concatenated during distribution.
  333.  
  334.  
  335. I am delighted to hear from you by letter or electronic mail about the
  336. plusses and problems of SIMPP, and any corrections and additions.  I cannot
  337. be your telephone consultant -- I'm hard to reach and very busy (who isn't!).
  338.  
  339. If you wish to use this package in a product, reprint, distribute, or use
  340. it in a some commercial way, please contact me about licensing.
  341.  
  342. Happy image processing!
  343.  
  344. Dr. Ben Dawson
  345. E10-120 M.I.T.            home:    89 Overbrook Drive.
  346. 79 Amherst St.                Wellesley, MA 02181
  347. Cambridge MA, 02139
  348.  
  349. Tel. (617) 253-5700
  350. ARPA net: BMD@OZ.AI.MIT.EDU
  351.  
  352. /* ================ End of simpp.doc ================ */
  353.  
  354. /* <-- FILE BREAK --> */
  355.